package ase.assignment.sts.ws.impl;

import java.rmi.RemoteException;

import ase.assignment.sts.api.CustomerHandler;
import ase.assignment.sts.api.HandlerFactory;
import ase.assignment.sts.api.PortfolioHandler;
import ase.assignment.sts.api.StockHandler;
import ase.assignment.sts.ws.customer.CustomerService;
import ase.assignment.sts.ws.customer.CustomerServiceLocator;

public class HandlerFactoryWSImpl implements HandlerFactory {

	public CustomerHandler getCustomerHandler() {
		return new CustomerHandlerWSImpl();
	}

	public PortfolioHandler getPortfolioHandler() {
		return new PortfolioHandlerWSImpl();
	}

	public StockHandler getStockHandler() {
		return new StockHandlerWSImpl();
	}

	public boolean isActive() throws RemoteException {
		try {
			// Test Web service activated
			javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory
					.newInstance();
			CustomerService customerService = new CustomerServiceLocator();
			java.net.URL url = new java.net.URL(customerService
					.getSTSCustomerAddress()
					+ "?WSDL");
			javax.xml.rpc.Service service = serviceFactory.createService(url,
					customerService.getServiceName());
			if (service != null) {
				return true;
			}
		} catch (Exception e) {
			// e.printStackTrace();
		}
		return false;
	}

}
